/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.ove.openmath.jome.ctrl.amto;

/**
 *
 * @author Mr.Sam
 */
import fr.ove.openmath.jome.ctrl.linear.events.LinearParserEvent;
import fr.ove.openmath.jome.ctrl.amto.Function;

/**
* The abstract math tree object of the lambda expression.
*
* @author © 1999 DIRAT Laurent
* @version 1.0  19/11/1999
*/
public class Lambda extends Function {
    /**
    * The constructor.
    * @param identifier the identifier of the instance.
    * @param token the identifier of the instance by the mean of the event sent.
    */
    public Lambda() {
        super("lambda");
    }
    
    /**
    * "Flushes" the object as a sequence of events for the building of the model
    */
    public void flush() {
        LinearParserEvent linearParserEvent = new LinearParserEvent(getEventSource());
        
        // The opening
        linearParserEvent.setToken(opening, param);
        fireLinearParserEvent(linearParserEvent);
        
        // we first flush the object of the lambda expression, then the bound variable(s).
        // (OM has the bound variable(s) first)
        
        int nbChildren = getNbChildren();
        int count = nbChildren - 1;
        flushChild(getChild(count), count);
        for (int i = 0; i < count; i++) {
            linearParserEvent.setToken(token, null);
            fireLinearParserEvent(linearParserEvent);
            flushChild(getChild(i), i);
        }
        
        // The closing
        linearParserEvent.setToken(closing, null);
        fireLinearParserEvent(linearParserEvent);
    }
}